<%@ page contentType="text/html;charset=UTF-8" language="java"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<table class="display" id="example">
    <thead>
    <tr>
        <th>选择</th>
        <th>部门</th>
        <th>岗位</th>
        <th>定性比率</th>
        <th>定量比率</th>
        <th>绩效占比</th>
        <th>周期</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <s:if test="#request.examBaseConfigPojos==null || #request.examBaseConfigPojos.size() <= 0">
        <tr class="gradeA"> <td colspan="8">暂无数据</td> </tr>
    </s:if>
    <s:else>
        <s:iterator value="#request.examBaseConfigPojos" var="config" status="sta">
            <s:if test="#sta.even"> <tr class="gradeA"> </s:if> <s:else> <tr class="gradeC"> </s:else>
            <td><input type="checkbox" name="check_config_o${organizationId}" value="${config.id}" duty_id="${config.duty.id}"/></td>
            <td>${config.duty.organization.fullName}</td>
            <td>${config.duty.dutyName}</td>
            <s:if test="#request.config.id == null or #request.config.id == 0">
            <td>未设定</td>
            <td>未设定</td>
            <td>未设定</td>
            <td>未设定</td>
            <td>
            <a class="button" href="#exam/base_config_add.xhtml?examBaseConfig.duty.id=${config.duty.id}&t=<%=new java.util.Date().getTime()%>"><span style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>新增</a>
            </td>
            </s:if>
            <s:else>
            <td>${config.percentageQualitative}%</td>
            <td>${config.percentageQuantitative}%</td>
            <td>${config.percentagePerformance}%</td>
            <td>${config.periodType.name}</td>
            <td>
            <a class="button" href="#exam/base_config_add.xhtml?examBaseConfig.id=${config.id}&t=<%=new java.util.Date().getTime()%>"><span style="background:url(${ctx}/images/img/page_edit.png)" class="icon">&nbsp;</span>修改</a>
            </td>
            </s:else>
            </tr>
        </s:iterator>
    </s:else>
    </tbody>
</table>

<p><%@ include file="/WEB-INF/pages/common/main_orgtab_pager.jsp"%></p>

<div class="tabs side grid_12 leading">
    <div class="clear"></div>
    <div class="grid_12">
        <div class="form-action clearfix">
            <p>
                <input type="checkbox" id="check_all" value="1" onchange="checkAll(this, 'check_config_o${organizationId}')"/>&nbsp;<label for="check_all">全选</label>
                <a href="javascript:void(0)" onclick="batchOperator('edit')" class="button"><span class="icon" style="background:url(${ctx}/images/img/page_edit.png)">&nbsp;</span>批量修改</a>
                <a class="button" href="javascript:void(0)" onclick="batchOperator('create')"><span style="background:url(${ctx}/images/img/add.png)" class="icon">&nbsp;</span>批量添加</a>
            </p>
        </div>
    </div>
</div>

<script type="text/javascript">
    function batchOperator(type){
        var duty_ids = new Array();
        var config_ids = new Array();
        var items = $("input[type='checkbox'][name='check_config_o${organizationId}']").each(function() {
            if($(this).attr("checked")){
                var configId = $(this).val();
                if(configId > 0){
                    config_ids.push(configId);
                }else{
                    duty_ids.push($(this).attr("duty_id"));
                }
            }
        });
        if(type == "edit"){
            if(config_ids.length == 0){
                alert("未选择修改项或批量修改的项全部未添加");
                return;
            }
            //alert("批量修改"+config_ids)
            window.location.href="#exam/base_config_batch_add.xhtml?batchType=edit&examBaseConfig.id="+config_ids[0]+"&batchIds="+config_ids.join(",");
        }else if(type == "create"){
            if(duty_ids.length == 0){
                alert("未选择添加项或批量添加的项全部已添加");
                return;
            }
            //alert("批量添加"+duty_ids)
            window.location.href="#exam/base_config_batch_add.xhtml?batchType=create&batchIds="+duty_ids.join(",");
        }
    }
</script>